﻿using MultiLang;

namespace VfNewMessages
{
    using System;
    using System.Drawing;
    using Rsdn.Janus;
    using Rsdn.Janus.CoreServices.NavigationTree;
    using Rsdn.Janus.Database;
    using Rsdn.SmartApp;

    public class VfNewMessagesItemInfo : INavigationTreeItemInfo
    {
        private readonly IServiceProvider provider;

        #region Implementation of INavigationTreeItemInfo

        public VfNewMessagesItemInfo(IServiceProvider provider)
        {
            this.provider = provider;
        }

        public int Id
        {
            get { return PredefinedExtensionIds.VfNewMessages; }
        }

        public string ItemKey
        {
            get { return GetType().Name; }
        }

        public int PositionOrder
        {
            get { return 100; }
        }

        public Func<string> DisplayNameFunc
        {
            get
            {
                Func<string> funcRet =
                    delegate
                        {
                            IForumQueryService forumQueryService =
                                ServiceProvider.GetRequiredService<IForumQueryService>();
                            DateTime lastUpdateDate = forumQueryService.LastUpdateDate;
                            IFormatMessageHelperService formatMessageService =
                                ServiceProvider.GetRequiredService<IFormatMessageHelperService>();

                            string dateTimeAsString =
                                formatMessageService.GetDateAsString(lastUpdateDate);

                            // Новые сообщения c {0}
                            // New messages from {0}
                            return string.Format(ml.ml_string(1, "Новые сообщения c {0}"), dateTimeAsString);
                        };
                return funcRet;
            }
        }

        public Func<string> AdditionalInfo
        {
            get { return () => "No additional info"; }                //MLHIDE
        }

        public Image ItemImage
        {
            get
            {
                return Properties.Resources.NewMessages;
            }
        }

        public string ContextMenuName
        {
            get { throw new NotImplementedException(); }
        }

        public IServiceProvider ServiceProvider
        {
            get { return provider; }
        }

        #endregion
    }
}